/**
 * 活动开窗
 * @author ganjia
 * @date 2019/01/21
 */
define(function () {

    var self,
        app = win.app,
        vueData = {
            selectType: '',
            tableData: [],
            count: 0,
            limit: 10,
            keyword: '',
            GWCS010: '',
            GWCSDOCDATE: '',
            GWCS117:'',
            gwdc005Options: [{
                value: '1',
                label: '1:裸价'
            }, {
                value: '2',
                label: '2:特价'
            }, {
                value: '3',
                label: '3:满额赠送'
            }, {
                value: '4',
                label: '4:满量赠送'
            }],
            gwdc004Options: [{
                value: '1',
                label: '1:组合'
            }, {
                value: '2',
                label: '2:非组合'
            }]
        },
        page = 1,
        cb
    ;

    app.newModule({
        init: function () {
            self = this;
            self._super({
                _tag: 'common_open_gwdc001'
            }, win);
        },
        queryDatas: function () {
            app.ajax({
                xurl: 'crm/gwai710/listGwdc001',
                xdata: {
                    page: page,
                    limit: vueData.limit,
                    keyword: vueData.keyword,
                    GWCS010: vueData.GWCS010, //客户编号
                    GWCSDOCDATE: vueData.GWCSDOCDATE,
                    GWCS117:vueData.GWCS117 //返利类型
                },
                cb: function (result) {
                    if (result.ok) {
                        vueData.tableData.pushArray(result.data.data, true);
                        vueData.count = result.data.count;
                    }
                }
            });
        },

        _call: function (obj) {
            cb = obj.cb;
            vueData.GWCS010 = obj.GWCS010;
            vueData.GWCSDOCDATE = obj.GWCSDOCDATE;
            vueData.GWCS117 = obj.GWCS117;
            if (obj.selectType == null) {
                obj.selectType = "singleTable";
            }
            vueData.selectType = obj.selectType;
            vueData.keyword = '';
            self.queryDatas();

        },

        _ready: function () {
            new Vue({
                el: '#common_open_gwdc001',
                data: vueData,
                methods: {
                    formatGwdc005: function (row, column) {
                        obj = vueData.gwdc005Options.find(function (item) {
                            return item.value === row.GWDC005
                        }).label;
                        if (obj != null) {
                            return obj;
                        } else {
                            row.GWDC005
                        }
                    },
                    formatGwdc004: function (row, column) {
                        obj = vueData.gwdc004Options.find(function (item) {
                            return item.value === row.GWDC004
                        }).label;
                        if (obj != null) {
                            return obj;
                        } else {
                            row.GWDC004
                        }
                    },
                    selectRow: function (inx, row) {
                        app.log(inx, row);
                        cb(row);
                        layer.close(layer.index);
                    },
                    handleSizeChange: function (val) {
                    },
                    handleCurrentChange: function (val) {
                        page = val;
                        self.queryDatas();
                    },
                    queryDatas: function () {
                        page = 1;
                        self.queryDatas();
                    },
                    cancle: function (rows) {
                        layer.close(layer.index);
                    },
                    handleSelectionChange: function (val) {
                        this.multipleSelection = val;
                        //layer.close(layer.index);
                    },
                    save: function () {
                        cb(this.multipleSelection);
                        this.multipleSelection = [];
                        layer.close(layer.index);
                    }
                },
                created: function () {
                    self._setEleIsReady('common_open_gwdc001');
                }
            });
        },
        _lazy: function () {
            this._super();
        }
    });

});